<?php
namespace BP\Sys;
require_once("java/io/BufferedInputStream.php");
require_once("java/io/BufferedOutputStream.php");
require_once("java/io/File.php");
require_once("java/io/FileInputStream.php");
require_once("java/io/IOException.php");
require_once("java/io/InputStream.php");
require_once("java/io/OutputStream.php");
require_once("java/io/UnsupportedEncodingException.php");
require_once("java/text/SimpleDateFormat.php");
require_once("java/util/ArrayList.php");
require_once("java/util/Date.php");
require_once("java/util/Enumeration.php");
require_once("java/util/Hashtable.php");
require_once("java/util/Iterator.php");
require_once("java/util/Set.php");
require_once("java/util/regex/Matcher.php");
require_once("java/util/regex/Pattern.php");
require_once("javax/servlet/ServletOutputStream.php");
require_once("javax/servlet/http/HttpServletRequest.php");
require_once("javax/servlet/http/HttpServletResponse.php");
require_once("BP/DA/DBAccess.php");
require_once("BP/DA/DBCheckLevel.php");
require_once("BP/DA/DBType.php");
require_once("BP/DA/DBUrlType.php");
require_once("BP/DA/DataColumn.php");
require_once("BP/DA/DataRow.php");
require_once("BP/DA/DataTable.php");
require_once("BP/DA/DataType.php");
require_once("BP/DA/Log.php");
require_once("BP/Difference/ContextHolderUtils.php");
require_once("BP/En/Attr.php");
require_once("BP/En/Attrs.php");
require_once("BP/En/ClassFactory.php");
require_once("BP/En/EnType.php");
require_once("BP/En/Entities.php");
require_once("BP/En/Entity.php");
require_once("BP/En/FieldType.php");
require_once("BP/En/Map.php");
require_once("BP/En/QueryObject.php");
require_once("BP/En/UIContralType.php");
require_once("BP/Sys/GroupField.php");
require_once("BP/Sys/MapAttr.php");
require_once("BP/Sys/MapData.php");
require_once("BP/Sys/MapDatas.php");
require_once("BP/Sys/MapDtl.php");
require_once("BP/Sys/MapDtls.php");
class PubClass {
	protected static $Color;	// String
	protected static $_KeyFields;	// String
	public static function __staticinit() { // static class members
		self::$Color = NULL;
		self::$_KeyFields = NULL;
	}
	public static function ToHtmlColor ($colorName) // [String colorName]
	{
		try 
		{
			if ($colorName->startsWith("#"))
			{
				$colorName = $colorName->replace("#", "");
				if ((($colorName->length() == 6) || ($colorName->length() == 3)))
				{
					return ("#" . $colorName);
				}
				else
					if (($colorName->length() == 8))
					{
						return ("#" . $colorName->substring(2, 8));
					}
					else
					{
						return ("#" . $colorName);
					}
			}
			else
			{
				return $colorName;
			}
		}
		catch (\Exception $e)
		{
			return "black";
		}
	}
	public static function DealToFieldOrTableNames ($fd) // [String fd]
	{
		$keys = "~!@#$%^&*()+{}|:<>?`=[];,./～！＠＃￥％…�?�＆×（）—�?�＋｛｝｜：“�?��?�？�?－＝［］；＇，．�?";
		$cc = $keys->toCharArray();
		foreach ($cc as $c) 		{
			$fd = $fd->replace((new Character($c)), "");
		}
		$s = $fd->substring(0, 1);
		try 
		{
			$a = $Integer->parseInt($s);
			$fd = ("F" . $fd);
		}
		catch (\Exception $e)
		{ /* empty */ }
		return $fd;
	}
	public static function getKeyFields () 
	{
		if ((self::$_KeyFields . NULL))
		{
			self::$_KeyFields =DataType->ReadTextFile((SystemConfig::getPathOfData() . "/Sys/FieldKeys.txt"));
		}
		return self::$_KeyFields;
	}
	public static function IsNum ($str) // [String str]
	{
		$strResult = null;
		$cn_Regex = "^[\\u4e00-\\u9fa5]+$";
		$pattern = $Pattern->compile($cn_Regex);
		$matcher = $pattern->matcher($str);
		if ($matcher->find())
		{
			$strResult =  TRUE ;
		}
		else
		{
			$strResult =  FALSE ;
		}
		return $strResult;
	}
	public static function IsCN ($str) // [String str]
	{
		$strResult = null;
		$cn_Regex = "^[\\u4e00-\\u9fa5]+$";
		$pattern = $Pattern->compile($cn_Regex);
		$matcher = $pattern->matcher($str);
		if ($matcher->find())
		{
			$strResult =  TRUE ;
		}
		else
		{
			$strResult =  FALSE ;
		}
		return $strResult;
	}
	public static function IsImg ($ext) // [String ext]
	{
		$ext = $ext->replace(".", "")->toLowerCase();
		if ($ext->equals("gif"))
		{
			return  TRUE ;
		}
		else
			if ($ext->equals("jpg"))
			{
				return  TRUE ;
			}
			else
				if ($ext->equals("bmp"))
				{
					return  TRUE ;
				}
				else
					if ($ext->equals("png"))
					{
						return  TRUE ;
					}
					else
					{
						return  FALSE ;
					}
	}
	public static function GenerImgW_del ($ObjH, $factH, $factW, $isZeroAsWith) // [int ObjH, int factH, int factW, int isZeroAsWith]
	{
		if ((($factH == 0) || ($factW == 0)))
		{
			return $isZeroAsWith;
		}
		$d = ($ObjH / (($factH * $factW)));
		try 
		{
			return $d;
		}
		catch (\RuntimeException $ex)
		{
			throw new \RuntimeException(($d + $ex->getMessage()));
		}
	}
	public static function GenerImgH ($ObjW, $factH, $factW, $isZeroAsWith) // [int ObjW, int factH, int factW, int isZeroAsWith]
	{
		if ((($factH == 0) || ($factW == 0)))
		{
			return $isZeroAsWith;
		}
		$d = ($ObjW / (($factW * $factH)));
		try 
		{
			return $d;
		}
		catch (\RuntimeException $ex)
		{
			throw new \RuntimeException(($d + $ex->getMessage()));
		}
	}
	public static function GenerLabelStr ($title) // [String title]
	{
		$path = Glo->getRequest()->getRemoteHost();
		if (($path->equals("") || $path->equals("/")))
		{
			$path = "..";
		}
		$str = "";
		$str += (("<TABLE  height='100%' cellPadding='0' background='" . $path) . "/Images/DG_bgright.gif'>");
		$str += "<TBODY>";
		$str += "<TR   >";
		$str += "<TD  >";
		$str += (("<IMG src='" . $path) . "/Images/DG_Title_Left.gif' border='0'></TD>");
		$str += (("<TD style='font-size:14px'  vAlign='bottom' noWrap background='" . $path) . "/Images/DG_Title_BG.gif'>&nbsp;");
		$str += ((" &nbsp;<b>" . $title) . "</b>&nbsp;&nbsp;");
		$str += "</TD>";
		$str += "<TD>";
		$str += (("<IMG src='" . $path) . "/Images/DG_Title_Right.gif' border='0'></TD>");
		$str += "</TR>";
		$str += "</TBODY>";
		$str += "</TABLE>";
		return $str;
	}
	public function Chs2Pinyin ($str) // [String str]
	{
		return $BP->Tools->chs2py->convert($str);
	}
	public static function GenerTablePage ($dt, $title) // [DataTable dt, String title]
	{
		$str = "<Table id='tb' class=Table >";
		$str += (("<caption>" . $title) . "</caption>");
		$str += "<TR>";
		foreach ($dt->Columns as $dc) 		{
			$str += (((("<TD class='DGCellOfHeader" . $BP->Web->WebUser->getStyle()) . "' nowrap >") . $dc->ColumnName) . "</TD>");
		}
		$str += "</TR>";
		foreach ($dt->Rows as $dr) 		{
			$str += "<TR>";
			foreach ($dt->Columns as $dc) 			{
				$str += (("<TD nowrap=true >&nbsp;" . $dr->getValue($dc->ColumnName)) . "</TD>");
			}
			$str += "</TR>";
		}
		$str += "</Table>";
		return $str;
	}
	public static function GenerTempFileName ($hz) // [String hz]
	{
		$formatter = new SimpleDateFormat("MMddhhmmss");
		return ((($BP->Web->WebUser->getNo() + $formatter->format(new Date())) . ".") . $hz);
	}
	public static function DeleteTempFiles () 
	{
		$file = new File(SystemConfig::getPathOfTemp());
		$strs = $file->listFiles();
		foreach ($strs as $s) 		{
			$s->delete();
		}
	}
	public static function ReCreateIndex () 
	{
		$als = $ClassFactory->GetObjects("BP.En.Entity");
		$sql = "";
		foreach ($als as $en) 		{
			if (($en->getEnMap()->getEnType() == $EnType->View))
			{
				continue;
			}
			$sql += (((("IF EXISTS( SELECT name  FROM  sysobjects WHERE  name='" . $en->getEnMap()->getPhysicsTable()) . "') <BR> DROP TABLE ") . $en->getEnMap()->getPhysicsTable()) . "<BR>");
			$sql += (("CREATE TABLE " . $en->getEnMap()->getPhysicsTable()) . " ( <BR>");
			$sql += "";
		}
	}
	public static function CheckAllPTable ($nameS) // [String nameS]
	{
		$al = $BP->En->ClassFactory->GetObjects("BP.En.Entities");
		foreach ($al as $ens) 		{
			if (!$ens->contains($nameS))
			{
				continue;
			}
			try 
			{
				$en = $ens->getNewEntity();
				$en->CheckPhysicsTable();
			}
			catch (\Exception $e)
			{ /* empty */ }
		}
	}
	public static function GetDataTableByUIBineKey ($uiBindKey) // [String uiBindKey]
	{
		$dt = new DataTable();
		if ($uiBindKey->contains("."))
		{
			$ens = $BP->En->ClassFactory->GetEns($uiBindKey);
			if (($ens == NULL))
				$ens = $BP->En->ClassFactory->GetEns($uiBindKey);
			if (($ens == NULL))
				$ens = $BP->En->ClassFactory->GetEns($uiBindKey);
			if (($ens == NULL))
				throw new Exception((("类名错误:" . $uiBindKey) . ",不能转化成ens."));
			$ens->RetrieveAllFromDBSource();
			$dt = $ens->ToDataTableField($uiBindKey);
			return $dt;
		}
		$sf = SFTable::constructor__();
		$sf->setNo($uiBindKey);
		if (($sf->RetrieveFromDBSources() != 0))
		{
			if ((($sf->getSrcType() == SrcType::$Handler) || ($sf->getSrcType() == SrcType::$JQuery)))
				return NULL;
			$dt = $sf->GenerHisDataTable();
		}
		if (($dt == NULL))
			$dt = new DataTable();
		foreach ($dt->Columns as $col) 		{
			$colName = $col->ColumnName->toLowerCase();
			if (($colName->equals("no") ==  TRUE ))
				$col->ColumnName = "No";
			if (($colName->equals("name") ==  TRUE ))
				$col->ColumnName = "Name";
			if (($colName->equals("parentno") ==  TRUE ))
				$col->ColumnName = "ParentNo";
		}
		$dt->TableName = $uiBindKey;
		return $dt;
	}
	public static function GetDataTableByUIBineKeyForCCFormDesigner ($uiBindKey) // [String uiBindKey]
	{
		$topNum = 40;
		$dt = new DataTable();
		if ($uiBindKey->contains("."))
		{
			$ens = $BP->En->ClassFactory->GetEns($uiBindKey);
			if (($ens == NULL))
			{
				$ens = $BP->En->ClassFactory->GetEns($uiBindKey);
			}
			if (($ens == NULL))
			{
				$ens = $BP->En->ClassFactory->GetEns($uiBindKey);
			}
			if (($ens == NULL))
			{
				throw new \RuntimeException((("类名错误:" . $uiBindKey) . ",不能转化成ens."));
			}
			$qo = new QueryObject($ens);
			return $qo->DoQueryToTable($topNum);
		}
		else
		{
			$sql = "";
			switch (SystemConfig::getAppCenterDBType()) {
				case $Oracle:
					$sql = ((("SELECT No,Name FROM " . $uiBindKey) . " where rowNum <= ") . $topNum);
					break;
				case $MSSQL:
					$sql = ((("SELECT top " . $topNum) . " No,Name FROM ") . $uiBindKey);
					break;
				default:
					$sql = ("SELECT  No,Name FROM " . $uiBindKey);
					break;
			}
			$dt =DBAccess->RunSQLReturnTable($sql);
			$dt->TableName = $uiBindKey;
			return $dt;
		}
	}
	public static function GenerDBOfOreacle () 
	{
		$als = $ClassFactory->GetObjects("BP.En.Entity");
		$sql = "";
		foreach ($als as $en) 		{
			$sql += (((("IF EXISTS( SELECT name  FROM  sysobjects WHERE  name='" . $en->getEnMap()->getPhysicsTable()) . "') <BR> DROP TABLE ") . $en->getEnMap()->getPhysicsTable()) . "<BR>");
			$sql += (("CREATE TABLE " . $en->getEnMap()->getPhysicsTable()) . " ( <BR>");
			$sql += "";
		}
		return $sql;
	}
	public static function DBRpt ($level) // [DBCheckLevel level]
	{
		$als = $ClassFactory->GetObjects("BP.En.Entities");
		$msg = "";
		foreach ($als as $ens) 		{
			try 
			{
				$msg += PubClass::DBRpt1($level, $ens);
			}
			catch (\RuntimeException $ex)
			{
				$msg += ((("<hr>" . $ens) . "体检失败:") . $ex->getMessage());
			}
		}
		$mds = MapDatas::constructor__();
		$mds->RetrieveAllFromDBSource();
		foreach ($mds as $md) 		{
			try 
			{
				try 
				{
					($md)->getHisGEEn()->CheckPhysicsTable();
				}
				catch (Exception $e)
				{
					$e->printStackTrace();
				}
			/* match: Entity */
				PubClass->AddComment_Entity(($md)->getHisGEEn());
			}
			catch (\RuntimeException $ex)
			{
				$msg += ((("<hr>" . ($md)->getNo()) . "体检失败:") . $ex->getMessage());
			}
		}
		$dtls = MapDtls::constructor__();
		$dtls->RetrieveAllFromDBSource();
		foreach ($dtls as $dtl) 		{
			try 
			{
				try 
				{
					($dtl)->getHisGEDtl()->CheckPhysicsTable();
				}
				catch (Exception $e)
				{
					$e->printStackTrace();
				}
			/* match: Entity */
				PubClass->AddComment_Entity(($dtl)->getHisGEDtl());
			}
			catch (\RuntimeException $ex)
			{
				$msg += ((("<hr>" . ($dtl)->getNo()) . "体检失败:") . $ex->getMessage());
			}
		}
		$sql = "";
		$sqls = "";
		$sql = "SELECT count(*) Num FROM Pub_Day";
		try 
		{
			$d = "";
			if ((DBAccess->RunSQLReturnValInt($sql) == 0))
			{
				for ($i = 1; ($i <= 31); ++$i) 
				{
					if (($i <= 9))
						$d = PubClass::addZeroForNum($String->valueOf($i), 2);
					else
						$d = $String->valueOf($i);
					$sqls += (((("@INSERT INTO Pub_Day(No,Name)VALUES('" . $d) . "','") . $d) . "')");
				}
			}
		}
		catch (\Exception $e)
		{ /* empty */ }
		$sql = "SELECT count(*) Num FROM Pub_YF";
		try 
		{
			$d1 = "";
			if ((DBAccess->RunSQLReturnValInt($sql) == 0))
			{
				for ($i = 1; ($i <= 12); ++$i) 
				{
					if (($i <= 9))
						$d1 = PubClass::addZeroForNum($String->valueOf($i), 2);
					else
						$d1 = $String->valueOf($i);
					$sqls += (((("@INSERT INTO Pub_YF(No,Name)VALUES('" . $d1) . "','") . $d1) . "')");
				}
			}
		}
		catch (\Exception $e2)
		{ /* empty */ }
		$sql = "SELECT count(*) Num FROM Pub_ND";
		try 
		{
			if ((DBAccess->RunSQLReturnValInt($sql) == 0))
			{
				for ($i = 2010; ($i < 2015); ++$i) 
				{
					$d = (new Integer($i));
					$sqls += (((("@INSERT INTO Pub_ND(No,Name)VALUES('" . $d) . "','") . $d) . "')");
				}
			}
		}
		catch (\Exception $e3)
		{ /* empty */ }
		$sql = "SELECT count(*) Num FROM Pub_NY";
		try 
		{
			$d2 = "";
			if ((DBAccess->RunSQLReturnValInt($sql) == 0))
			{
				for ($i = 2010; ($i < 2015); ++$i) 
				{
					for ($yf = 1; ($yf <= 12); ++$yf) 
					{
						if (($i <= 9))
							$d2 = (((new Integer($i)) . "-") . PubClass::addZeroForNum($String->valueOf($i), 2));
						else
							$d2 = (((new Integer($i)) . "-") . $String->valueOf($i));
						$sqls += (((("@INSERT INTO Pub_NY(No,Name)VALUES('" . $d2) . "','") . $d2) . "')");
					}
				}
			}
		}
		catch (\Exception $e4)
		{ /* empty */ }
		try 
		{
			DBAccess->RunSQLs($sqls);
		}
		catch (Exception $e)
		{
			$e->printStackTrace();
		}
		return $msg;
	}
	public static function addZeroForNum ($str, $strLength) // [String str, int strLength]
	{
		$strLen = $str->length();
		$sb = NULL;
		while (($strLen < $strLength)) 
		{
			$sb = ''; //
			$sb->append("0")->append($str);
			$str = $sb;
			$strLen = $str->length();
		}
		return $str;
	}
	public static function AddComment () 
	{
		$als = $ClassFactory->GetObjects("BP.En.Entities");
		$msg = "";
		$en = NULL;
		foreach ($als as $ens) 		{
			if (($ens == NULL))
				continue;
			try 
			{
				$en = $ens->getNewEntity();
				if ((($en->getEnMap()->getEnType() == $EnType->View) || ($en->getEnMap()->getEnType() == $EnType->ThirdPartApp)))
				{
					continue;
				}
			}
			catch (\Exception $e)
			{
				continue;
			}
			if ((($en->getEnMap()->getPhysicsTable() != NULL) && !$en->getEnMap()->getPhysicsTable()->equals("null")))
			{
			/* match: Entity */
				$msg += PubClass->AddComment_Entity($en);
			}
		}
		return $msg;
	}
	public static function AddComment_Entity ($en) // [Entity en]
	{
		if ((DBAccess->IsExitsObject($en->getEnMap()->getPhysicsTable()) ==  FALSE ))
			return "表不存在.";
		try 
		{
			switch (SystemConfig::getAppCenterDBType()) {
				case $Oracle:
					PubClass::AddCommentForTable_Ora($en);
					break;
				case $MySQL:
					PubClass::AddCommentForTable_MySql($en);
					break;
				default:
					PubClass::AddCommentForTable_MS($en);
					break;
			}
			return "";
		}
		catch (\RuntimeException $ex)
		{
			return ((("<hr>" . $en) . "体检失败:") . $ex->getMessage());
		}
		catch (Exception $e)
		{
			$e->printStackTrace();
			return NULL;
		}
	}
	public static function AddCommentForTable_Ora ($en) // [Entity en]
	{
		$en->RunSQL((((("comment on table " . $en->getEnMap()->getPhysicsTable()) . " IS '") . $en->getEnDesc()) . "'"));
		$ses = SysEnums::constructor__();
		foreach ($en->getEnMap()->getAttrs() as $attr) 		{
			if (($attr->getMyFieldType() == $FieldType->RefText))
			{
				continue;
			}
			switch ($attr->getMyFieldType()) {
				case $PK:
					$en->RunSQL((((((("comment on column  " . $en->getEnMap()->getPhysicsTable()) . ".") . $attr->getField()) . " IS '") . $attr->getDesc()) . " - 主键'"));
					break;
				case $Normal:
					$en->RunSQL((((((("comment on column  " . $en->getEnMap()->getPhysicsTable()) . ".") . $attr->getField()) . " IS '") . $attr->getDesc()) . "'"));
					break;
				case $Enum:
					$ses = SysEnums::constructor__String_String($attr->getKey(), $attr->UITag);
					$en->RunSQL((((((((("comment on column  " . $en->getEnMap()->getPhysicsTable()) . ".") . $attr->getField()) . " IS '") . $attr->getDesc()) . ",枚举类型:") . $ses->ToDesc()) . "'"));
					break;
				case $PKEnum:
					$ses = SysEnums::constructor__String_String($attr->getKey(), $attr->UITag);
					$en->RunSQL((((((((("comment on column  " . $en->getEnMap()->getPhysicsTable()) . ".") . $attr->getField()) . " IS '") . $attr->getDesc()) . ", 主键:枚举类型:") . $ses->ToDesc()) . "'"));
					break;
				case $FK:
					$myen = $attr->getHisFKEn();
					$en->RunSQL((((((((((("comment on column  " . $en->getEnMap()->getPhysicsTable()) . ".") . $attr->getField()) . " IS '") . $attr->getDesc()) . ", 外键:对应物理�?:") . $myen->getEnMap()->getPhysicsTable()) . ",表描�?:") . $myen->getEnDesc()) . "'"));
					break;
				case $PKFK:
					$myen1 = $attr->getHisFKEn();
					$en->RunSQL((((((((((("comment on column  " . $en->getEnMap()->getPhysicsTable()) . ".") . $attr->getField()) . " IS '") . $attr->getDesc()) . ", 主外�?:对应物理�?:") . $myen1->getEnMap()->getPhysicsTable()) . ",表描�?:") . $myen1->getEnDesc()) . "'"));
					break;
				default:
					break;
			}
		}
	}
	public static function AddCommentForTable_MySql ($en) // [Entity en]
	{
		$database = SystemConfig::getAppCenterDBDatabase();
		$en->RunSQL((((((("alter table " . $database) . ".") . $en->getEnMap()->getPhysicsTable()) . " comment = '") . $en->getEnDesc()) . "'"));
		$cols = DBAccess->RunSQLReturnTable((((("select column_name,column_default,is_nullable,character_set_name,column_type from information_schema.columns where table_schema = '" . $database) . "' and table_name='") . $en->getEnMap()->getPhysicsTable()) . "'"));
		$ses = SysEnums::constructor__();
		$sql = "";
		$row = NULL;
		foreach ($en->getEnMap()->getAttrs() as $attr) 		{
			if (($attr->getMyFieldType() == $FieldType->RefText))
			{
				continue;
			}
			$row = $cols->select($String->format("column_name='%1$s'", $attr->getField()))->get(0);
			$sql = $String->format("ALTER TABLE %1$s.%2$s CHANGE COLUMN %3$s %3$s %4$s%5$s%6$s%7$s COMMENT ", $database, $en->getEnMap()->getPhysicsTable(), $attr->getField(), $row->getValue("column_type")->toUpperCase(), ( ($row->getValue("character_set_name")->equals("utf8")) ? " CHARACTER SET 'utf8'" : "" ), ( ($row->getValue("is_nullable")->equals("YES")) ? " NULL" : " NOT NULL" ), ( ($row->getValue("column_default")->equals("NULL")) ? " DEFAULT NULL" : (( ($row->getValue("")->equals("")) ? "" : (" DEFAULT " . $row->getValue((""))) )) ));
			switch ($attr->getMyFieldType()) {
				case $PK:
					$en->RunSQL(($sql . $String->format("'%1$s - 主键'", $attr->getDesc())));
					break;
				case $Normal:
					$en->RunSQL(($sql . $String->format("'%1$s'", $attr->getDesc())));
					break;
				case $Enum:
					$ses = SysEnums::constructor__String_String($attr->getKey(), $attr->UITag);
					$en->RunSQL(($sql . $String->format("'%1$s,枚举类型:%2$s'", $attr->getDesc(), $ses->ToDesc())));
					break;
				case $PKEnum:
					$ses = SysEnums::constructor__String_String($attr->getKey(), $attr->UITag);
					$en->RunSQL(($sql . $String->format("'%1$s,主键:枚举类型:%2$s'", $attr->getDesc(), $ses->ToDesc())));
					break;
				case $FK:
					$myen = $attr->getHisFKEn();
					$en->RunSQL(($sql . $String->format("'%1$s,外键:对应物理�?:%2$s,表描�?:%3$s'", $attr->getDesc(), $myen->getEnMap()->getPhysicsTable(), $myen->getEnDesc())));
					break;
				case $PKFK:
					$myen1 = $attr->getHisFKEn();
					$en->RunSQL(($sql . $String->format("'%1$s,主外�?:对应物理�?:%2$s,表描�?:%3$s'", $attr->getDesc(), $myen1->getEnMap()->getPhysicsTable(), $myen1->getEnDesc())));
					break;
				default:
					break;
			}
		}
	}
	protected static function AddColNote ($en, $table, $col, $note) // [Entity en, String table, String col, String note]
	{
		return ;
	}
	public static function AddCommentForTable_MS ($en) // [Entity en]
	{
		if ((($en->getEnMap()->getEnType() == $EnType->View) || ($en->getEnMap()->getEnType() == $EnType->ThirdPartApp)))
		{
			return ;
		}
		try 
		{
			$sql = (("execute  sp_dropextendedproperty 'MS_Description','user',dbo,'table','" . $en->getEnMap()->getPhysicsTable()) . "'");
			$en->RunSQL($sql);
		}
		catch (\RuntimeException $ex)
		{ /* empty */ }
		catch (Exception $e)
		{
			$e->printStackTrace();
		}
		try 
		{
			$sql = (((("execute  sp_addextendedproperty 'MS_Description', '" . $en->getEnDesc()) . "', 'user', dbo, 'table', '") . $en->getEnMap()->getPhysicsTable()) . "'");
			$en->RunSQL($sql);
		}
		catch (\RuntimeException $ex)
		{ /* empty */ }
		catch (Exception $e)
		{
			$e->printStackTrace();
		}
		$ses = SysEnums::constructor__();
		foreach ($en->getEnMap()->getAttrs() as $attr) 		{
			if (($attr->getMyFieldType() == $FieldType->RefText))
			{
				continue;
			}
			if ($attr->getKey()->equals($attr->getDesc()))
			{
				continue;
			}
			switch ($attr->getMyFieldType()) {
				case $Normal:
					PubClass::AddColNote($en, $en->getEnMap()->getPhysicsTable(), $attr->getField(), $attr->getDesc());
					break;
				case $Enum:
					$ses = SysEnums::constructor__String_String($attr->getKey(), $attr->UITag);
					PubClass::AddColNote($en, $en->getEnMap()->getPhysicsTable(), $attr->getField(), (($attr->getDesc() . ",枚举类型:") . $ses->ToDesc()));
					break;
				case $PKEnum:
					$ses = SysEnums::constructor__String_String($attr->getKey(), $attr->UITag);
					PubClass::AddColNote($en, $en->getEnMap()->getPhysicsTable(), $attr->getField(), (($attr->getDesc() . ",主键:枚举类型:") . $ses->ToDesc()));
					break;
				case $FK:
					$myen = $attr->getHisFKEn();
					PubClass::AddColNote($en, $en->getEnMap()->getPhysicsTable(), $attr->getField(), (((($attr->getDesc() . ", 外键:对应物理�?:") . $myen->getEnMap()->getPhysicsTable()) . ",表描�?:") . $myen->getEnDesc()));
					break;
				case $PKFK:
					$myen1 = $attr->getHisFKEn();
					PubClass::AddColNote($en, $en->getEnMap()->getPhysicsTable(), $attr->getField(), (((($attr->getDesc() . ", 主外�?:对应物理�?:") . $myen1->getEnMap()->getPhysicsTable()) . ",表描�?:") . $myen1->getEnDesc()));
					break;
				default:
					break;
			}
		}
	}
	public static function DBRpt1 ($level, $ens) // [DBCheckLevel level, Entities ens]
	{
		$en = $ens->getNewEntity();
		if (($en->getEnMap()->getEnDBUrl()->getDBUrlType() != $DBUrlType->AppCenterDSN))
		{
			return NULL;
		}
		if (($en->getEnMap()->getEnType() == $EnType->ThirdPartApp))
		{
			return NULL;
		}
		if (($en->getEnMap()->getEnType() == $EnType->View))
		{
			return NULL;
		}
		if (($en->getEnMap()->getEnType() == $EnType->Ext))
		{
			return NULL;
		}
		try 
		{
			$en->CheckPhysicsTable();
		}
		catch (Exception $e1)
		{
			$e1->printStackTrace();
		}
			/* match: Entity */
		PubClass->AddComment_Entity($en);
		$msg = "";
		$table = $en->getEnMap()->getPhysicsTable();
		$fkAttrs = $en->getEnMap()->getHisFKAttrs();
		if (($fkAttrs->size() == 0))
		{
			return $msg;
		}
		$num = 0;
		$sql = null;
		foreach ($fkAttrs as $attr) 		{
			if (($attr->getMyFieldType() == $FieldType->RefText))
			{
				continue;
			}
			$enMsg = "";
			try 
			{
				if ((($level == $DBCheckLevel->Middle) || ($level == $DBCheckLevel->High)))
				{
					if (($attr->getMyDataType() == $DataType->AppString))
					{
						DBAccess::RunSQL((((((("UPDATE " . $en->getEnMap()->getPhysicsTable()) . " SET ") . $attr->getField()) . " = rtrim( ltrim(") . $attr->getField()) . ") )"));
					}
				}
				$refEns = $attr->getHisFKEns();
				$refEn = $refEns->getNewEntity();
				$reftable = $refEn->getEnMap()->getPhysicsTable();
				$sql = (("SELECT COUNT(*) FROM  sysobjects  WHERE  name = '" . $reftable) . "'");
				if (!DBAccess->IsExitsObject($reftable))
				{
					$enMsg += ((((((((("<br>@�?查实体：" . $en->getEnDesc()) . ",字段 ") . $attr->getKey()) . " , 字段描述:") . $attr->getDesc()) . " , 外键物理�?:") . $reftable) . "不存�?:") . $sql);
				}
				else
				{
					$attrRefKey = $refEn->getEnMap()->GetAttrByKey($attr->getUIRefKeyValue());
					if (($attrRefKey->getMyDataType() == $DataType->AppString))
					{
						if ((($level == $DBCheckLevel->Middle) || ($level == $DBCheckLevel->High)))
						{
							DBAccess::RunSQL((((((("UPDATE " . $reftable) . " SET ") . $attrRefKey->getField()) . " = rtrim( ltrim(") . $attrRefKey->getField()) . ") )"));
						}
					}
					$attrRefText = $refEn->getEnMap()->GetAttrByKey($attr->getUIRefKeyText());
					if ((($level == $DBCheckLevel->Middle) || ($level == $DBCheckLevel->High)))
					{
						DBAccess::RunSQL((((((("UPDATE " . $reftable) . " SET ") . $attrRefText->getField()) . " = rtrim( ltrim(") . $attrRefText->getField()) . ") )"));
					}
				}
				switch (SystemConfig::getAppCenterDBType()) {
					case $Oracle:
						$sql = (((((("SELECT COUNT(*) FROM " . $en->getEnMap()->getPhysicsTable()) . " WHERE ") . $attr->getField()) . " is null or length(") . $attr->getField()) . ") < 1 ");
						break;
					default:
						$sql = (((((("SELECT COUNT(*) FROM " . $en->getEnMap()->getPhysicsTable()) . " WHERE ") . $attr->getField()) . " is null or len(") . $attr->getField()) . ") < 1 ");
						break;
				}
				$num =DBAccess->RunSQLReturnValInt($sql, 0);
				if (($num == 0))
				else
				{
					$enMsg += ((((((((((("<br>@�?查实体：" . $en->getEnDesc()) . ",物理�?:") . $en->getEnMap()->getPhysicsTable()) . "出现") . $attr->getKey()) . ",") . $attr->getDesc()) . "不正�?,共有[") . $num) . "]行记录没有数据�??") . $sql);
				}
				$sql = (((((((("SELECT COUNT(*) FROM " . $en->getEnMap()->getPhysicsTable()) . " WHERE ") . $attr->getField()) . " NOT IN ( SELECT ") . $refEn->getEnMap()->GetAttrByKey($attr->getUIRefKeyValue())->getField()) . " FROM ") . $reftable) . "	 ) ");
				$num =DBAccess->RunSQLReturnValInt($sql, 0);
				if (($num == 0))
				else
				{
					$delsql = (((((((("DELETE FROM " . $en->getEnMap()->getPhysicsTable()) . " WHERE ") . $attr->getField()) . " NOT IN ( SELECT ") . $refEn->getEnMap()->GetAttrByKey($attr->getUIRefKeyValue())->getField()) . " FROM ") . $reftable) . "	 ) ");
					$enMsg += (((((((((((((("<br>@" . $en->getEnDesc()) . ",物理�?:") . $en->getEnMap()->getPhysicsTable()) . "出现") . $attr->getKey()) . ",") . $attr->getDesc()) . "不正�?,共有[") . $num) . "]行记录没有关联到数据，请�?查物理表与外键表�?") . $sql) . "如果您想删除这些对应不上的数据请运行如下SQL: ") . $delsql) . " 请慎重执�?.");
				}
			}
			catch (\RuntimeException $ex)
			{
				$enMsg += ("<br>@" . $ex->getMessage());
			}
			catch (Exception $e)
			{
				$e->printStackTrace();
			}
			if (!$enMsg->equals(""))
			{
				$msg += (((((("<BR><b>-- �?查[" . $en->getEnDesc()) . ",") . $en->getEnMap()->getPhysicsTable()) . "]出现如下问题,类名�?:") . $en) . "</b>");
				$msg += $enMsg;
			}
		}
		return $msg;
	}
	public static function OpenExcel ($filepath, $tempName) // [String filepath, String tempName]
	{
		$response = $ContextHolderUtils->getResponse();
		$request = $ContextHolderUtils->getRequest();
		$response->setContentType("application/ms-excel;charset=UTF-8");
		$response->setCharacterEncoding("UTF-8");
		$response->setHeader("Content-Disposition", ("inline;filename=" . new String($tempName->getBytes("UTF-8"), "ISO-8859-1")));
		$bos = NULL;
		$fis = NULL;
		try 
		{
			$file = new File($filepath);
			if (!$file->exists())
			{
				throw new Exception(("找不到指定文件：" . $filepath));
			}
			$fis = new FileInputStream($file);
			$bos = new BufferedOutputStream($response->getOutputStream());
			$b = array();
			$data = 0;
			while ((($data = $fis->read($b)) != -1)) 
			{
				$bos->write($b, 0, $data);
			}
			$bos->flush();
		}
		catch (Exception $e)
		{ /* empty */ }
		finally {
		{
			if (($bos != NULL))
				$bos->close();
			if (($fis != NULL))
				$fis->close();
		}
		}
	}
	public static function toUtf8String_String ($s) // [String s]
	{
		$sb = ''; //
		for ($i = 0; ($i < $s->length()); ++$i) 
		{
// 			$c = $s->charAt($i);
		    $c = substr($s, $i, 1);
			if ((($c >= 0) && ($c <= 255)))
			{
				$sb->append($c);
			}
			else
			{
				$b = null;
				try 
				{
					$b = $Character->toString($c)->getBytes("utf-8");
				}
				catch (Exception $ex)
				{
					$b = array();
				}
				for ($j = 0; ($j < count($b) /*from: b.length*/); ++$j) 
				{
					$k = $b[$j];
					if (($k < 0))
						$k += 256;
					$sb->append(("%" . $Integer->toHexString($k)->toUpperCase()));
				}
			}
		}
		return $sb;
	}
	public static function toUtf8String_HttpServletRequest_String ($request, $s) // [HttpServletRequest request, String s]
	{
		$agent = $request->getHeader("User-Agent");
		try 
		{
			$isFireFox = ((($agent . NULL) . ($agent->toLowerCase()->indexOf("firefox") != -1)));
			if ($isFireFox)
			{
				$s = new String($s->getBytes("UTF-8"), "ISO8859-1");
			}
			else
			{
			/* match: String */
				$s = PubClass->toUtf8String_String($s);
				if (((($agent . NULL) . ($agent->indexOf("MSIE") != -1))))
				{
					if (($s->length() > 150))
					{
						$s = new String($s->getBytes("UTF-8"), "ISO8859-1");
					}
				}
			}
		}
		catch (UnsupportedEncodingException $e)
		{
			$e->printStackTrace();
		}
		return $s;
	}
	public static function DownloadFile ($filepath, $tempName) // [String filepath, String tempName]
	{
		$response = $ContextHolderUtils->getResponse();
		$request = $ContextHolderUtils->getRequest();
			/* match: HttpServletRequest_String */
		$tempName = PubClass->toUtf8String_HttpServletRequest_String($request, $tempName);
		$myfile = new File($filepath);
		if (($myfile->exists() ==  FALSE ))
			throw new Exception(("err@文件名不存在:" . $filepath));
		$response->reset();
		$response->setContentType("application/octet-stream");
		$response->setHeader("Content-Disposition", ("attachment;filename=" . $tempName));
		$response->setHeader("Connection", "close");
		$in = new FileInputStream($myfile);
		$out = $response->getOutputStream();
		$b = null;
		while ((($b = $in->read()) != -1)) 
		{
			$out->write($b);
		}
		$in->close();
		$out->close();
	}
	public static function DownloadFileByBuffer ($filepath, $tempName) // [String filepath, String tempName]
	{
		$response = $ContextHolderUtils->getResponse();
		$request = $ContextHolderUtils->getRequest();
			/* match: HttpServletRequest_String */
		$tempName = PubClass->toUtf8String_HttpServletRequest_String($request, $tempName);
		$response->reset();
		$response->setContentType("application/octet-stream");
		$response->setHeader("Content-Disposition", ("attachment;filename=" . $tempName));
		$response->setHeader("Connection", "close");
		$in = new FileInputStream(new File($filepath));
		$bis = new BufferedInputStream($in);
		$out = $response->getOutputStream();
		$bos = new BufferedOutputStream($out);
		$b = null;
		while ((($b = $bis->read()) != -1)) 
		{
			$bos->write($b);
			$bos->flush();
		}
		$in->close();
		$bis->close();
		$out->close();
		$bos->close();
	}
	public static function DownloadHttpFile ($filepath, $tempName, $response) // [String filepath, String tempName, HttpServletResponse response]
	{
		$byteList = [];// 
		$response->setHeader("Content-Type", "application/octet-stream; charset=UTF-8");
		$response->setHeader("Content-Disposition", ("attachment; filename=" . $tempName));
		$filePth = $filepath->replace("\\", "/")->trim();
		if (($filepath->indexOf("/") == 0))
		{
			$filepath = $filepath->substring(($filepath->length() - 1));
		}
		if (!SystemConfig::getAttachWebSite()->trim()->endsWith("/"))
		{
			$filepath = ((SystemConfig::getAttachWebSite()->trim() . "/") . $filepath);
		}
		else
		{
			$filepath = (SystemConfig::getAttachWebSite()->trim() . $filepath);
		}
		$fis = new FileInputStream($filepath);
		$data = array();
		$os = $response->getOutputStream();
		$i = null;
		while ((($i = $fis->read($data, 0, 8192)) != -1)) 
		{
			$os->write($data, 0, $i);
		}
		$os->flush();
		$fis->close();
		$os->close();
	}
	public static function OpenWordDocV2 ($filepath, $tempName) // [String filepath, String tempName]
	{
		$response = $ContextHolderUtils->getResponse();
		$request = $ContextHolderUtils->getRequest();
		$response->setContentType("application/msword;charset=UTF-8");
		$response->setCharacterEncoding("UTF-8");
		$response->setHeader("Content-Disposition", ("inline;filename=" . new String($filepath->getBytes("GB2312"), "ISO-8859-1")));
		$bos = NULL;
		$fis = NULL;
		try 
		{
			$file = new File($filepath);
			if (!$file->exists())
			{
				throw new Exception(("找不到指定文件：" . $filepath));
			}
			$fis = new FileInputStream($file);
			$bos = new BufferedOutputStream($response->getOutputStream());
			$b = array();
			$data = 0;
			while ((($data = $fis->read($b)) != -1)) 
			{
				$bos->write($b, 0, $data);
			}
			$bos->flush();
		}
		catch (Exception $e)
		{ /* empty */ }
		finally {
		{
			if (($bos != NULL))
				$bos->close();
			if (($fis != NULL))
				$fis->close();
		}
		}
	}
	public static function HashtableToDataTable ($ht) // [Hashtable ht]
	{
		$dt = new DataTable();
		$dt->TableName = "Hashtable";
		$keys = $ht->keySet();
		foreach ($keys as $key) 		{
			$dt->Columns->Add($key, String);
		}
		$dr = $dt->NewRow();
		foreach ($keys as $key) 		{
			$dr->setValue($key, $ht->get($key));
		}
		$dt->Rows->add($dr);
		return $dt;
	}
	public static function Print ($url) // [String url]
	{
		try 
		{
			$ContextHolderUtils->getResponse()->getWriter()->write((("<script language='JavaScript'> var newWindow =window.open('" . $url) . "','p','width=0,top=10,left=10,height=1,scrollbars=yes,resizable=yes,toolbar=yes,location=yes,menubar=yes') ; newWindow.focus(); </script> "));
		}
		catch (IOException $e)
		{
			$e->printStackTrace();
		}
	}
	public static function copyFromRequest ($en, $reqest) // [BP.En.Entity en, HttpServletRequest reqest]
	{
		$requestKeys = [];// 
		$enu = $reqest->getParameterNames();
		while ($enu->hasMoreElements()) 
		{
			$key = $enu->nextElement();
			$requestKeys->add($key);
		}
		$attrs = $en->getEnMap()->getAttrs();
		foreach ($attrs as $item) 		{
			$relKey = NULL;
			switch ($item->getUIContralType()) {
				case $TB:
					$relKey = ("TB_" . $item->getKey());
					break;
				case $CheckBok:
					$relKey = ("CB_" . $item->getKey());
					break;
				case $DDL:
					$relKey = ("DDL_" . $item->getKey());
					break;
				case $RadioBtn:
					$relKey = ("RB_" . $item->getKey());
					break;
				default:
					break;
			}
			if ($requestKeys->contains($relKey))
			{
				$index = $requestKeys->indexOf($relKey);
				$myK = $requestKeys->get($index);
				if ((($myK . NULL) . $myK->equals("")))
				{
					continue;
				}
				if (($item->getUIContralType() == $UIContralType->CheckBok))
				{
					$val = $reqest->getParameter($myK);
					if (($val->equals("on") || $val->equals("1")))
					{
						$en->SetValByKey($item->getKey(), 1);
					}
					else
					{
						$en->SetValByKey($item->getKey(), 0);
					}
				}
				else
				{
					$value = $reqest->getParameter($myK)->trim();
					$en->SetValByKey($item->getKey(), $value);
				}
				continue;
			}
			else
			{
				if (((NULL . $relKey) . $relKey->contains("CB_")))
				{
					$en->SetValByKey($item->getKey(), 0);
				}
			}
		}
		return $en;
	}
	public static function WinClose () 
	{
		$clientscript = "<script language='javascript'> window.close(); </script>";
		try 
		{
			$ContextHolderUtils->getResponse()->setContentType("text/html; charset=utf-8");
			$ContextHolderUtils->getResponse()->getWriter()->write($clientscript);
		}
		catch (IOException $e)
		{
			$e->printStackTrace();
		}
	}
	public static function WinOpen_HttpServletResponse_String ($response, $url) // [HttpServletResponse response, String url]
	{
		$df = new SimpleDateFormat("MMddHHmmss");
			/* match: HttpServletResponse_String_String_String_I_I */
		PubClass->WinOpen_HttpServletResponse_String_String_String_I_I($response, $url, "", ("msg" . $df->format(new Date())), 300, 300);
	}
	public static function WinOpen_HttpServletResponse_String_I_I ($response, $url, $w, $h) // [HttpServletResponse response, String url, int w, int h]
	{
		$df = new SimpleDateFormat("MMddHHmmss");
			/* match: HttpServletResponse_String_String_String_I_I */
		PubClass->WinOpen_HttpServletResponse_String_String_String_I_I($response, $url, "", ("msg" . $df->format(new Date())), $w, $h);
	}
	public static function WinOpen_HttpServletResponse_String_String_String_I_I ($response, $url, $title, $winName, $width, $height) // [HttpServletResponse response, String url, String title, String winName, int width, int height]
	{
			/* match: HttpServletResponse_String_String_String_I_I_I_I */
		PubClass->WinOpen_HttpServletResponse_String_String_String_I_I_I_I($response, $url, $title, $winName, $width, $height, 100, 200);
	}
	public static function WinOpen_HttpServletResponse_String_String_I_I ($response, $url, $title, $width, $height) // [HttpServletResponse response, String url, String title, int width, int height]
	{
			/* match: HttpServletResponse_String_String_String_I_I_I_I */
		PubClass->WinOpen_HttpServletResponse_String_String_String_I_I_I_I($response, $url, $title, "ActivePage", $width, $height, 100, 200);
	}
	public static function WinOpen_HttpServletResponse_String_String_String_I_I_I_I ($response, $url, $title, $winName, $width, $height, $top, $left) // [HttpServletResponse response, String url, String title, String winName, int width, int height, int top, int left]
	{
		$url = $url->replace("<", "[");
		$url = $url->replace(">", "]");
		$url = $url->trim();
		$title = $title->replace("<", "[");
		$title = $title->replace(">", "]");
		$title = $title->replace("\"", "�?");
		if ((($top == 0) && ($left == 0)))
		{
			$response->getWriter()->write((((((((("<script language='JavaScript'> var newWindow =window.open('" . $url) . "','") . $winName) . "','width=") . $width) . ",top=") . $top) . ",scrollbars=yes,resizable=yes,toolbar=false,location=false') ; </script> "));
			$response->getWriter()->flush();
		}
		else
		{
			$response->getWriter()->write((((((((((((("<script language='JavaScript'> var newWindow =window.open('" . $url) . "','") . $winName) . "','width=") . $width) . ",top=") . $top) . ",left=") . $left) . ",height=") . $height) . ",scrollbars=yes,resizable=yes,toolbar=false,location=false');</script>"));
			$response->getWriter()->flush();
		}
	}
	public static function ResponseWriteBlueMsg ($msg) // [String msg]
	{
		throw new Exception("");
	}
	public static function ToErrorPage ($mess, $response) // [String mess, HttpServletResponse response]
	{
		Glo->getRequest()->getSession()->setAttribute("info", $mess);
		try 
		{
			$response->sendRedirect((($BP->WF->Glo->getCCFlowAppPath() . "WF/Comm/Port/ToErrorPage.htm?d=") . new Date()));
		}
		catch (IOException $e)
		{
			$e->printStackTrace();
		}
	}
	public static function ToMsgPage ($mess, $response) // [String mess, HttpServletResponse response]
	{
		$mess = $mess->replace("@", "<BR>@");
		Glo->getRequest()->getSession()->setAttribute("info", $mess);
		try 
		{
			$response->sendRedirect((($BP->WF->Glo->getCCFlowAppPath() . "WF/Comm/Port/InfoPage.jsp?d=") . new Date()));
		}
		catch (IOException $e)
		{
			$e->printStackTrace();
		}
	}
	public static function Alert ($mess, $response) // [String mess, HttpServletResponse response]
	{
		$script = (("<script language=JavaScript>alert('" . $mess) . "');</script>");
		try 
		{
			$response->setCharacterEncoding("gbk");
			$response->getWriter()->write($script);
		}
		catch (IOException $e)
		{
			$e->printStackTrace();
		}
	}
	public static function ResponseWriteScript ($script) // [String script]
	{
		$script = (("<script language=JavaScript> " . $script) . "</script>");
		try 
		{
			$ContextHolderUtils->getResponse()->getWriter()->write($script);
		}
		catch (IOException $e)
		{
			$e->printStackTrace();
		}
	}
	public static function CopyFromRequest_EntityEnBP ($en) // [BP.En.Entity en]
	{
			/* match: EntityEnBP_HttpServletRequest */
		return PubClass->CopyFromRequest_EntityEnBP_HttpServletRequest($en, Glo::getRequest());
	}
	public static function CopyFromRequest_EntityEnBP_HttpServletRequest ($en, $reqest) // [BP.En.Entity en, HttpServletRequest reqest]
	{
		$allKeys = ";";
		$checkBoxIDs = $reqest->getParameter("CheckBoxIDs");
		if (($checkBoxIDs . NULL))
		{
			$strs = $checkBoxIDs->split(",");
			foreach ($strs as $str) 			{
				if ((($str == NULL) || $str->equals("")))
					continue;
				$en->SetValByKey($str->replace("CB_", ""), 0);
			}
		}
		for ($iter = Glo::getRequest()->getParameterMap()->keySet()->iterator(); $iter->hasNext(); ) 
		{
			$key = $iter->next();
			if ((($key . NULL) . $key->equals("")))
				continue;
			$attrKey = $key;
			if ($key->startsWith("TB_"))
				$attrKey = $attrKey->replace("TB_", "");
			else
				if ($key->startsWith("CB_"))
					$attrKey = $attrKey->replace("CB_", "");
				else
					if ($key->startsWith("DDL_"))
						$attrKey = $attrKey->replace("DDL_", "");
					else
						if ($key->startsWith("RB_"))
							$attrKey = $attrKey->replace("RB_", "");
						else
							continue;
			$val = $reqest->getParameter($key);
			$en->SetValByKey($attrKey, $val);
		}
		return $en;
	}
	public static function CopyFromRequestByPost ($en, $reqest) // [BP.En.Entity en, HttpServletRequest reqest]
	{
		$allKeys = ";";
		$checkBoxIDs = Glo::getRequest()->getParameter("CheckBoxIDs");
		if (($checkBoxIDs . NULL))
		{
			$strs = $checkBoxIDs->split(",");
			foreach ($strs as $str) 			{
				if ((($str == NULL) || "" /* from: "".equals(str) */))
					continue;
				if ($str->contains("CBPara"))
				{
					$en->getRow()->SetValByKey($str->replace("CBPara_", ""), 0);
				}
				else
				{
					$en->getRow()->SetValByKey($str->replace("CB_", ""), 0);
				}
			}
		}
		for ($iter = Glo::getRequest()->getParameterMap()->keySet()->iterator(); $iter->hasNext(); ) 
		{
			$myK = $iter->next();
			$allKeys += ($myK . ";");
		}
		$attrs = $en->getEnMap()->getAttrs();
		foreach ($attrs as $item) 		{
			$relKey = NULL;
			switch ($item->getUIContralType()) {
				case $TB:
					$relKey = ("TB_" . $item->getKey());
					break;
				case $CheckBok:
					$relKey = ("CB_" . $item->getKey());
					break;
				case $DDL:
					$relKey = ("DDL_" . $item->getKey());
					break;
				case $RadioBtn:
					$relKey = ("RB_" . $item->getKey());
					break;
				default:
					break;
			}
			if (($relKey . NULL))
			{
				continue;
			}
			if ($allKeys->contains(($relKey . ";")))
			{
				for ($iter = Glo::getRequest()->getParameterMap()->keySet()->iterator(); $iter->hasNext(); ) 
				{
					$myK = $iter->next();
					if ((($myK . NULL) . "" /* from: "".equals(myK) */))
					{
						continue;
					}
					$val = Glo::getRequest()->getParameter($myK);
					if ($myK->endsWith($relKey))
					{
						if (($item->getUIContralType() == $UIContralType->CheckBok))
						{
							if ((($myK->indexOf("CB_") == 0) || ($myK->indexOf("CBPara_") == 0)))
							{
								$en->SetValByKey($item->getKey(), 1);
							}
						}
						else
						{
							$en->SetValByKey($item->getKey(), $val);
						}
					}
				}
				continue;
			}
		}
		return $en;
	}
}
PubClass::__staticinit(); // initialize static vars for this class on load
?>
